//
//  HHTransitionSample.swift
//  HHSwiftuiPractice
//
//  Created by YL-Hong on 2023/10/7.
//  Transition可用于为视图的出现、消失等变化添加自定义的过渡动画效果

import SwiftUI

struct HHTransitionSample: View {
    
    @State private var showMessage = false
    
    var body: some View {
        ZStack(alignment: .bottom) {
            VStack {
                       Button(action: {
                           withAnimation(.spring()) {
                               self.showMessage.toggle()
                           }
                       }) {
                           Text("SHOW MESSAGE")
                       }
                       
                       Spacer()
                   }
            
            if showMessage {
                   RoundedRectangle(cornerRadius: 25)
                       .frame(height: UIScreen.main.bounds.height * 0.5)
//                       .transition(AnyTransition.opacity) // 透明度动画
//                       .transition(AnyTransition.slide) //效果非常像一个push动画一样，默认从右到左
//                       .transition(.scale) //缩放动画
//                       .transition(.move(edge: .bottom))//移动动画
                       .transition(.asymmetric(insertion: .move(edge: .top), removal: .move(edge: .bottom)))//进入动画：从底部弹出 消失抽屉动画

               }
            
        }.edgesIgnoringSafeArea(.bottom)
    }
}

struct HHTransitionSample_Previews: PreviewProvider {
    static var previews: some View {
        HHTransitionSample()
    }
}
